#include "crossbit/ExecutionEngine.h"
#include "crossbit/CFG.h"
#include "crossbit/ELFMemoryImage.h"
#include "crossbit/SimpleTCache.h"
#include "crossbit/NextUseRegAllocator.h"
#include "crossbit/VFilter.h"
#include "crossbit/ShadowPage.h"
#include "arch/ia32/IA32Interpreter.h"
#include "arch/ia32/IA32ProcessorState.h"
#include "arch/ia32/IA32VBasicBlockBuilder.h"
#include "arch/ia32/IA32Syscall.h"
#include "arch/x86/X86Translator.h"
#include "arch/x86/X86TraceManager.h"
#include "arch/x86/X86.h"
#include "polytope/Polytope.h"

#define TCACHE_SIZE	1024*1024*10

//#define VFILTERS

extern char** environ;

using namespace crossbit;
using namespace polytope;

int main(int argc, char *argv[])
{
	ShadowPage sp;
	MemoryManager*	mm = MemoryManager::getInstance();
	SimpleTCache	tcache( TCACHE_SIZE, mm );

	ELFMemoryImage 	img( (XTPStr)argv[1], (XTUint32)(argc-1), (XTPStr*)&argv[1], (XTPStr*)environ );	
	IA32ProcessorState ps;
	IA32Interpreter interp(&ps, &img, &sp);
	IA32VBasicBlockBuilder builder;

#ifdef VFILTERS
	MemoryAccessFilter		maFilter;

	VFilter::registerFilter(&maFilter, VFilter::FLOAT_BASIC_BLOCK);
#endif

	NextUseRegAllocator alloc( 8, X86::movwMemToReg, X86::movwRegToMem, X86::movwRegToReg);
	X86Translator	tr( &ps, &alloc );
	X86TraceManager trace( mm );
	IA32Syscall sh(&ps, &img);
	CFG cfg_builder;
	Polytope polytope_builder;

	ExecutionEngine ee( &img, mm, &trace, &interp, &builder, &tcache, &tr, &sh, &ps, &cfg_builder , &polytope_builder);
	ee.run(0);

	return 0;
}

